package com.hainatong.shiphelper.module.workermgr.fragment;

import java.util.List;

import com.blankj.utilcode.util.ToastUtils;
import com.hainatong.shiphelper.MvvmLazyFragment;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.FragmentExpendlistViewBinding;
import com.hainatong.shiphelper.module.warehouse.entity.OrgUser;
import com.hainatong.shiphelper.module.warehouse.entity.ShipOrgBean;
import com.hainatong.shiphelper.module.workermgr.adapter.OrgExpandableAdapter;
import com.hainatong.shiphelper.module.workermgr.viewmodel.OrgUserViewModel;

import android.view.View;

public class DepartmentFragment extends MvvmLazyFragment<FragmentExpendlistViewBinding, OrgUserViewModel>
{
    private List<ShipOrgBean> shipOrgList;

    private OrgExpandableAdapter orgAdapter;

    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_expendlist_view;
    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick() {
    }

    @Override
    protected void initView(View view)
    {

        orgAdapter = new OrgExpandableAdapter( getActivity() );
        viewDataBinding.expandListview.setAdapter( orgAdapter );
        viewDataBinding.expandListview.setOnChildClickListener( (parent, v, groupPosition, childPosition, id) -> {
            OrgUser mOrg=((OrgUser)orgAdapter.getChild(groupPosition, childPosition));

            ToastUtils.showShort( mOrg.getUuid() );

            return false;
        });

    }

    @Override
    protected void lazyLoad()
    {

        // 先 查询 人员 组织
        viewModel.queryOrgUserListByLan("zh");
        viewModel.getOrgUserResult().observe( this ,result -> {
            if( result.isSuccess() )
            {
                shipOrgList = result.getData();
                orgAdapter.setShipOrgBeans( shipOrgList );
            }
            else
            {
                ToastUtils.showShort( result.getMsg() );
            }
        } );
    }
}
